package com.wxmit.ot.extensions.java.util.Map;

import manifold.ext.rt.api.Extension;
import manifold.rt.api.util.Pair;
import org.springframework.util.Assert;

import java.util.HashMap;
import java.util.Map;

/**
 * OtMapExtension
 *
 * @author huangxiong
 * @version V1.0
 * @date 2023/2/22 16:51
 */
@Extension
public class OtMapExtension {

    @Extension
    public static Map of(Object ...arg){
        Assert.isTrue(!arg.isNullOrEmpty(),"Map of arg[] can't be null or empty!");
        Assert.isTrue(arg.length%2 == 0,"Map of arg length must be an even number");
        Pair[] pairs = new Pair[arg.length/2];
        for(int i = 0,pi = 0,len = arg.length;i < len; i = i + 2 , pi++){
            pairs[pi] = Pair.make(arg[i],arg[i+1]);
        }
        return Map.mapOf(pairs);
    }

}
